<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <!-- <form action="postGetParameter" method="POST">
        <input type="text" name="userId">
        <input type="text" name="classId">
        <input type="submit" value="提交">
    </form> -->
      


        <!-- 想构造一个json格式的请求，就不在使用form表单了，而是使用ajax -->
        <input type="text" id="userId">
        <input type="text" id="classId">
        <input type="button" value="提交" id="submit">
   

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script>
        // $.ajax({
        //     type:'post',
        //     url:'method',
        //     success:function(body){
        //         console.log(body);
                

        //     }

        // });


        let userIdinput=document.querySelector("#userId");
        let classIdinput=document.querySelector("#classId");
        let button=document.querySelector("#submit");
        button.onclick=function(){
            $.ajax({
                type:'post',
                url:'postJson',
                contentType:'application/json',
                data:JSON.stringify({
                    userId:userIdinput.value,
                    classId:classIdinput.value

                }),
                success:function(body){
                    console.log(body);
                    
                }



            });


        }
    </script>



</body>
</html>